package com.hoas.quickstart.threads.chapter03.chapter03_3;

public class ThreadLocalTest {

    private static ThreadLocal<String> stringThreadLocal = ThreadLocal.withInitial(() -> "initialValue");

    private static ThreadLocal<Integer> integerThreadLocal = ThreadLocal.withInitial(() -> 0);

    public static void main(String[] args) throws InterruptedException {

        Thread thread1 = new Thread(() -> {
            stringThreadLocal.set("thread-1");
            integerThreadLocal.set(129);
            System.out.println(String.format("%s-----stringThreadLocalValue=%s",
                    Thread.currentThread().getName(), stringThreadLocal.get()));
            System.out.println(String.format("%s-----integerThreadLocalValue=%s",
                    Thread.currentThread().getName(), integerThreadLocal.get()));

        }, "thread-1");
        thread1.start();
        thread1.join();

        System.out.println(String.format("%s-----stringThreadLocalValue=%s",
                Thread.currentThread().getName(), stringThreadLocal.get()));
        System.out.println(String.format("%s-----integerThreadLocalValue=%s",
                Thread.currentThread().getName(), integerThreadLocal.get()));
    }


}
